package com.bangcommunity.bbframe.mlog.collector;

import com.bangcommunity.bbframe.common.utils.thread.CommonThreadPoolManager;

import java.util.concurrent.atomic.AtomicReference;

/**
 * @author tanghc
 * @date 18/1/30
 */
public class CollectorHelper {

    public static <T> T updateRefrence(AtomicReference<T> reference, final T update, RefrenceOperator<T> operator) {
        T current;
        do {
            current = reference.get();
            if (null != operator) {
                operator.opreate(current, update);
            }
        } while (!reference.compareAndSet(current, update));
        return current;
    }

    public static void asynCollect(Runnable runnable) {
        CommonThreadPoolManager.getInstance().addThread(runnable);
    }
}
